#include "stdafx.h"
#include "../Include/TickHelper.h"


#define DEF_MSG_ENTRY(msg)  {msg, L#msg}
static struct
{
    UINT message;
    LPCTSTR szMsg;
} g_MsgEntries[] =
{
    DEF_MSG_ENTRY(WM_CREATE),
    DEF_MSG_ENTRY(WM_TIMER),
    DEF_MSG_ENTRY(WM_SYSCOMMAND),
};
typedef std::map<UINT, XString> MsgEntryMap;
MsgEntryMap g_MsgEntryMap;

EXPORT_XDIAG XString GetWmMsgName(UINT message)
{
    if(g_MsgEntryMap.size() == 0)
    {
        for(int i=0; i<_countof(g_MsgEntries); ++ i)
        {
            g_MsgEntryMap.insert(std::make_pair(g_MsgEntries[i].message, g_MsgEntries[i].szMsg));
        }
    }

    XString strResult;

    MsgEntryMap::iterator entry = g_MsgEntryMap.find(message);
    if(entry != g_MsgEntryMap.end())
        strResult = entry->second;

    return strResult.Format(_T("0x%x"), message);
}

EXPORT_XDIAG XString GetWmMsgData(UINT message, WPARAM wParam, LPARAM lParam)
{
    XString strResult;
    strResult.Format(_T("Msg: %s, wParam: 0x%08x, lParam: 0x%08x"), GetWmMsgName(message).GetData(), wParam, lParam);
    return strResult;
}
